package cn.iocoder.yudao.module.member.level.controller.app;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.member.level.convert.MemberLevelConvert;
import cn.iocoder.yudao.module.member.level.dal.dataobject.MemberLevelDO;
import cn.iocoder.yudao.module.member.level.service.MemberLevelService;
import cn.iocoder.yudao.module.member.level.vo.AppMemberLevelRespVO;
import cn.iocoder.yudao.module.member.level.vo.AppMemberLevelSimpleRespVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.annotation.security.PermitAll;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

@Tag(name = "用户 App - 等级")
@RestController
@RequestMapping("/member/level")
@Validated
public class AppMemberLevelController {

    @Resource
    private MemberLevelService levelService;

    @GetMapping("/list")
    @Operation(summary = "获得等级列表")
    @PermitAll
    public CommonResult<List<AppMemberLevelRespVO>> getLevelList() {
        List<MemberLevelDO> result = levelService.getEnableLevelList();
        return success(MemberLevelConvert.INSTANCE.convertList02(result));
    }

    @GetMapping("/my")
    @Operation(summary = "获得等级信息")
    public CommonResult<AppMemberLevelSimpleRespVO> getMyLevel() {
        MemberLevelDO level = levelService.getLevel(getLoginUserId());
        return success(BeanUtils.toBean(level, AppMemberLevelSimpleRespVO.class));
    }

}
